//
//  LPSignSuccessShowView.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/7/10.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "LPSignSuccessShowView.h"

@interface LPSignSuccessShowView ()
/**  backView  */
@property (strong, nonatomic) UIView  *backView;
/**  知道了  */
@property (strong, nonatomic) UIButton  *sureButton;
/**  backImageView  */
@property (strong, nonatomic) UIImageView  *backImageView;

@end
@implementation LPSignSuccessShowView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor zj_colorWithR:20 G:20 B:20 Al:0.3];
        [self addSubview:self.backView];
        [self.backView addSubview:self.sureButton];
        [self.backView addSubview:self.backImageView];
        self.sureButton.sd_layout
        .bottomSpaceToView(self.backView, 15 * [UIScreen zj_screenHScale])
        .centerXEqualToView(self.backView)
        .widthIs(120 * [UIScreen zj_screenWScale])
        .heightIs(35 * [UIScreen zj_screenHScale]);
        
        self.backImageView.frame = CGRectMake(10 * [UIScreen zj_screenWScale], 20 * [UIScreen zj_screenHScale], self.backView.width - 20 * [UIScreen zj_screenWScale], 200 * [UIScreen zj_screenHScale]);
        
        
    }
    return self;
}

- (void)setData:(NSArray *)data{
    _data = data;
    CGFloat widtht = 0.0;
    CGFloat widthl = 0.0;
    NSMutableArray *imageAndTitle = [NSMutableArray array];
    if (data.count == 1) {
        NSDictionary *dic = @{@"image": @"pop_Integral", @"number": [NSString stringWithFormat:@"%@积分",data[0]]};
        [imageAndTitle addObject:dic];
        widtht = (self.backImageView.width - 100 * [UIScreen zj_screenHScale]) / 2;
        widthl = (self.backView.width - 100 * [UIScreen zj_screenHScale]) / 2;
    }else{
        NSDictionary *dic2 = @{@"image": @"pop_dot", @"number": [NSString stringWithFormat:@"%@分享点",data[0]]};
        [imageAndTitle addObject:dic2];

        NSDictionary *dic1 = @{@"image": @"pop_Integral", @"number": [NSString stringWithFormat:@"%@积分",data[1]]};
        [imageAndTitle addObject:dic1];
        widtht = (self.backImageView.width - 100 * [UIScreen zj_screenHScale] * 2) / 3;
        widthl = (self.backView.width - 100 * [UIScreen zj_screenHScale] * 2) / 3;

    
    }
    for (int i = 0; i < imageAndTitle.count; i ++) {
        UIImageView *tupian = [UIImageView new];
        tupian.image = [UIImage imageNamed:imageAndTitle[i][@"image"]];
        tupian.contentMode = UIViewContentModeScaleToFill;
        UILabel *label = [UILabel new];
        label.text = imageAndTitle[i][@"number"];
        label.textColor = [UIColor textGrayColor];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = LYPFONT(15);
        
        tupian.frame = CGRectMake(widtht + (100 * [UIScreen zj_screenHScale] + widtht) * i, 80 * [UIScreen zj_screenHScale], 110 * [UIScreen zj_screenHScale], 100 * [UIScreen zj_screenHScale]);
        [self.backImageView addSubview:tupian];
        label.frame = CGRectMake(widthl + + (100 * [UIScreen zj_screenHScale] + widthl) * i , self.backImageView.bottom + 5 * [UIScreen zj_screenHScale], 100 * [UIScreen zj_screenHScale], 20 * [UIScreen zj_screenHScale]);
        [self.backView addSubview:label];
       
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self removeFromSuperview];
}

- (void)clickButton{
    [self removeFromSuperview];
}

- (UIView *)backView{
    if (!_backView) {
        _backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith] * 0.9, 310 * [UIScreen zj_screenHScale])];
        _backView.center = self.center;
        _backView.backgroundColor = [UIColor whiteColor];
        _backView.layer.masksToBounds = YES;
        _backView.layer.cornerRadius = 6;
    }
    return _backView;
}

- (UIButton *)sureButton{
    if (!_sureButton) {
        _sureButton = [UIButton new];
        _sureButton.backgroundColor = [UIColor themeColor];
        [_sureButton setTitle:@"知道了" forState:UIControlStateNormal];
        [_sureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _sureButton.titleLabel.font = LYPFONT(16);
        _sureButton.layer.cornerRadius = 6;
        _sureButton.layer.masksToBounds = YES;
        [_sureButton addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sureButton;
}

- (UIImageView *)backImageView{
    if (!_backImageView) {
        _backImageView = [UIImageView new];
        _backImageView.image = [UIImage imageNamed:@"pop_bg"];
    }
    return _backImageView;
}
@end
